<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        background-color: #f8aba6;
      }
      .all {
        /* position: absolute; */
        width: 320px;
        height: 320px;
        background-color: #009ad6;
        border-radius: 50%;
      }
      .outher,
      .wapper {
        position: relative;
        width: 300px;
        height: 300px;
        border-radius: 50%;
        background-color: beige;
        overflow: hidden;
        margin: 0 auto;
        top: 50%;
        margin-top: -150px;
      }

      .wapper {
        transform: rotate(12.25deg);
      }

      .left,
      .right {
        width: 150px;
        height: 100%;
        overflow: hidden;
        position: absolute;
      }

      .left div {
        transform-origin: right center;
      }

      .right div {
        transform-origin: left center;
      }

      .left {
        left: 0;
        /* background-color: burlywood; */
      }

      .right {
        right: 0;
        /* background-color: blue; */
      }

      .left div,
      .right div {
        position: absolute;
        width: 150px;
        height: 100%;
        /* background-color: #; */
      }

      /* 左颜色 */
      .left .one {
        background-color: #7bbfea;
      }

      .left .two {
        background-color: #d3d7d4;
        transform: rotate(-22.5deg);
      }

      .left .three {
        background-color: #7bbfea;
        transform: rotate(-45deg);
      }

      .left .four {
        background-color: #d3d7d4;
        transform: rotate(-67.5deg);
      }

      .left .five {
        background-color: #7bbfea;
        transform: rotate(-90deg);
      }

      .left .six {
        background-color: #d3d7d4;
        transform: rotate(-112.5deg);
      }

      .left .seven {
        background-color: #7bbfea;
        transform: rotate(-135deg);
      }

      .left .eight {
        background-color: #d3d7d4;
        transform: rotate(-157.5deg);
      }

      /* 右颜色 */

      .right .one {
        background-color: #d3d7d4;
      }

      .right .two {
        background-color: #7bbfea;
        transform: rotate(22.5deg);
      }

      .right .three {
        background-color: #d3d7d4;
        transform: rotate(45deg);
      }

      .right .four {
        background-color: #7bbfea;
        transform: rotate(67.5deg);
      }

      .right .five {
        background-color: #d3d7d4;
        transform: rotate(90deg);
      }

      .right .six {
        background-color: #7bbfea;
        transform: rotate(112.5deg);
      }

      .right .seven {
        background-color: #d3d7d4;
        transform: rotate(135deg);
      }

      .right .eight {
        background-color: #7bbfea;
        transform: rotate(157.5deg);
      }

      .wapper span {
        width: 20px;
      }

      .left .text {
        position: absolute;
        left: 82%;
        top: 8px;
        transform: rotate(-10deg);
      }

      .right .text {
        position: absolute;
        left: 10%;
        top: 8px;
        transform: rotate(15deg);

      }

      .circle {
        position: absolute;
        width: 90px;
        height: 90px;
        border-radius: 50%;
        background-color: #009ad6;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        line-height: 90px;
        font-size: 30px;
        text-align: center;
        font-weight: bold;
        cursor: pointer;
        user-select: none;
        color: rgb(223, 219, 219);
      }
      .text{
        font-size: 14px;
      }
      .circle::after {
        content: "";
        position: absolute;
        top: -70px;
        left: 50%;
        transform: translate(-50%);
        border: 40px solid #009ad6;
        border-left-width: 10px;
        border-right-width: 10px;
        border-left-color: transparent;
        border-top-color: transparent;
        border-right-color: transparent;
      }
    </style>
  </head>

  <body>
    <div class="all">
      <div class="outher">
        <div class="wapper">
          <div class="left">
            <div class="one"><span class="text">螺蛳粉</span></div>
            <div class="two"><span class="text">咕咕鸡</span></div>
            <div class="three"><span class="text">自选菜</span></div>
            <div class="four"><span class="text">套餐饭</span></div>
            <div class="five"><span class="text">鸭梨先生</span></div>
            <div class="six"><span class="text">亦鱼亦饭</span></div>
            <div class="seven"><span class="text">重庆小面</span></div>
            <div class="eight"><span class="text">皖北特色面</span></div>
          </div>
          <div class="right">
            <div class="one"><span class="text">锡纸饭</span></div>
            <div class="two"><span class="text">麻辣烫</span></div>
            <div class="three"><span class="text">焖面</span></div>
            <div class="four"><span class="text">酸菜肉煲</span></div>
            <div class="five"><span class="text">烤肉拌饭</span></div>
            <div class="six"><span class="text">掉渣饼</span></div>
            <div class="seven"><span class="text">杂粮煎饼</span></div>
            <div class="eight"><span class="text">馄饨</span></div>
          </div>
        </div>
        <div class="circle">抽奖</div>
      </div>
      <script>
        let wapper = document.querySelector(".wapper");
        let textAll = document.querySelectorAll(".text");
        let texts = [
          "螺蛳粉",
          "咕咕鸡",
          "自选菜",
          "套餐饭",
          "鸭梨先生",
          "亦鱼亦饭",
          "重庆小面",
          "皖北特色面",
          "锡纸饭",
          "麻辣烫",
          "焖面",
          "酸菜肉煲",
          "烤肉拌饭",
          "掉渣饼",
          "杂粮煎饼",
          "馄饨",
        ];
        for (let i = 0; i < texts.length; i++) {
          textAll[i].innerHTML = texts[i];
        }
        let weight = [1, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98];

        let isFlag = true;

        document.querySelector(".circle").onclick = function () {
          if (isFlag) {
            let random = parseInt(Math.random() * 100);
            let randomWeight = weight.concat(random);
            let aa = randomWeight.sort(function (a, b) {
              return a - b;
            });
            console.log(aa);
            let randomIndex = aa.indexOf(random);
            switch (randomIndex) {
              case 0:
                run(6.125, texts[randomIndex]);
                break;
              case 1:
                run(18.375, texts[randomIndex]);
                break;
              case 2:
                run(30.625, texts[randomIndex]);
                break;
              case 3:
                run(42.875, texts[randomIndex]);
                break;
              case 4:
                run(55.125, texts[randomIndex]);
                break;
              case 5:
                run(67.375, texts[randomIndex]);
                break;
              case 6:
                run(79.625, texts[randomIndex]);
                break;
              case 7:
                run(91.875, texts[randomIndex]);
                break;
              case 8:
                run(104.125, texts[randomIndex]);
                break;
              case 9:
                run(116.375, texts[randomIndex]);
                break;
              case 10:
                run(128.625, texts[randomIndex]);
                break;
              case 11:
                run(140.875, texts[randomIndex]);
                break;
              case 12:
                run(153.125, texts[randomIndex]);
                break;
              case 13:
                run(165.375, texts[randomIndex]);
                break;
              case 14:
                run(177.625, texts[randomIndex]);
                break;
              case 15:
                run(189.875, texts[randomIndex]);
                break;
              case 16:
                run(202.125, texts[randomIndex]);
                break;
            }
          }
        };
        let timer = null;
        function run(angle, text) {
          isFlag = false;
          let begin = 0;
          let basic = 1800;
          timer = setInterval(function () {
            if (begin >= +(basic + angle)) {
              isFlag = true;
              clearInterval(timer);
            }
            wapper.style.transform = "rotate(" + begin + "deg)";
            begin += Math.ceil((basic + angle - begin) * 0.1);
          }, 50);
        }
      </script>
    </div>
  </body>
</html>
